package com.cizzy.relation.controller;

import com.cizzy.relation.common.Result;
import com.cizzy.relation.entity.Relation;
import com.cizzy.relation.entity.dto.UserDTO;
import com.cizzy.relation.entity.vo.FollowRequest;
import com.cizzy.relation.service.IRelationService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import javax.annotation.Resource;

import static com.cizzy.relation.config.CizzyFinal.PAGE_SIZE;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author crissy-月下闲人
 * @since 2023-11-03
 */
@RestController
@RequestMapping("/relation")
public class RelationController {
//    @Resource
    @Autowired
    private IRelationService relationService;

//    @ResponseBody
//    @GetMapping("/toConcern/{id}")
//    public Result<String> toConcern(@PathVariable("id") Long id) {
//        return relationService.toConcern(id);
//    }

    @ResponseBody
    @PostMapping("/follow")
    public Result<Relation> createFollow(@RequestBody FollowRequest followRequest) {
        System.out.println(followRequest.toString());
        return relationService.createFollow(followRequest);
    }

    @ResponseBody
    @PostMapping("/cancelFollow")
    public Result<Relation> cancelFollow(@RequestBody FollowRequest followRequest) {
        return relationService.cancelFollow(followRequest);
    }

    @ResponseBody
    @GetMapping("/isFollowed/{userId}/{targetId}")
    public Result<Boolean> isFollowed(@PathVariable("userId") Long userId, @PathVariable("targetId") Long targetId) {
        return relationService.isFollowed(userId, targetId);
    }

    @ResponseBody
    @GetMapping("/getFollowById/{userId}")
    public Result<List<UserDTO>> getFollowById(@PathVariable("userId") Long userId) {
        return relationService.getFollowById(userId);
    }

    @ResponseBody
    @GetMapping("/getFollowPageById/{userId}/{page}")
    public Result<List<UserDTO>> getFollowPageById(@PathVariable("userId") Long userId, @PathVariable("page") Integer page) {
        return relationService.getFollowPageById(userId, page, PAGE_SIZE);
    }

    @ResponseBody
    @GetMapping("/getFollowerById/{userId}")
    public Result<List<UserDTO>> getFollowerById(@PathVariable("userId") Long userId) {
        return relationService.getFollowerById(userId);
    }

    @ResponseBody
    @GetMapping("/getFollowerPageById/{targetId}/{page}")
    public Result<List<UserDTO>> getFollowerPageById(@PathVariable("targetId") Long targetId, @PathVariable("page") Integer page) {
        return relationService.getFollowerPageById(targetId, page, PAGE_SIZE);
    }

    /**
     * 通过 userId 获取关注数量
     *
     * @param userId
     * @return
     */
//    @GetMapping("/targetIds")
//    Result<List<Long>> getTargetIds(@RequestParam Long userId) {
//        return relationService.getTargetIds(userId);
//    }
//
//    @GetMapping("/targetUsers")
//    Result<List<UserDTO>> getTargetUsers(@RequestParam Long userId) {
//        return relationService.getTargetUsers(userId);
//    }
//
//    @GetMapping("/getFans")
//    Result<List<UserDTO>> getFans(@RequestParam Long userId) {
//        return relationService.getFans(userId);
//    }
}
